﻿
namespace Orz.Framework.Core.Publisher
{
    using Orz.Framework.Core.Messaging;

    /// <summary>
    /// Provide a adapter of publisher.
    /// </summary>
    public abstract class PublisherAdapter : IPublisher
    {
        TypeMessenger messenger = SingletonManager.GetInstance<TypeMessenger>();

        /// <summary>
        /// Publish the message.
        /// </summary>
        /// <param name="message">The message.</param>
        public virtual void OnMessage(object message)
        {
            if (message != null)
            {
                messenger.NotifyAll(message);
            }
        }

        /// <summary>
        /// Publish the message asynchronously.
        /// </summary>
        /// <param name="message">The message.</param>
        public virtual void OnMessageAsyn(object message)
        {
            if (message != null)
            {
                messenger.NotifyAllAsyn(message);
            }
        }

        #region IDisposable Members

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public virtual void Dispose() { }

        #endregion
    }
}
